From 967b9e05e28ee6d7ad71bc54bec8ea2bd7727323 Mon Sep 17 00:00:00 2001 From: Michael Schumacher Date: Sat, 6 Jan 2007 14:21:14 +0000 Subject: [PATCH] This change makes babl buildable on Windows. 2007-01-06 Michael Schumacher This change makes babl buildable on Windows. * configure.ac: Add a check for function dlopen and disabled static libs by default. Check for gettimeofday by using AC_REPLACE_FUNCS. * babl/babl-internal.h: Add definitions for srandom and radnom to srand and rand for the windows platform. * babl/babl-conversion.c * babl-model.c: Include babl-internal.h after math.h * babl/babl-extension.c: Use #ifdef HAVE_DLOPEN to hide dl* if it is not available. * babl/Makefile.am: Removed win32_libs and added @LTLIBOBJS@ to LIBADD to get the replacement for gettimeofday linked in if needed. * babl/gettimeofday.c: New file to provide a replacement for gettimeofday, only used on Windows yet. svn path=/trunk/; revision=193 --- ChangeLog | 23 +++++++++++++++ babl/Makefile.am | 3 +- babl/babl-conversion.c | 5 ++-- babl/babl-extension.c | 9 ++---- babl/babl-internal.h | 5 ++++ babl/babl-model.c | 2 +- babl/gettimeofday.c | 66 ++++++++++++++++++++++++++++++++++++++++++ configure.ac | 4 +++ 8 files changed, 106 insertions(+), 11 deletions(-) create mode 100644 babl/gettimeofday.c diff --git a/ChangeLog b/ChangeLog index 16ee3d8..3774cff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2007-01-06 Michael Schumacher + + This change makes babl buildable on Windows. + + * configure.ac: Add a check for function dlopen and disabled + static libs by default. Check for gettimeofday by using + AC_REPLACE_FUNCS. + + * babl/babl-internal.h: Add definitions for srandom and radnom to + srand and rand for the windows platform. + * babl/babl-conversion.c + * babl-model.c: Include babl-internal.h after math.h + + * babl/babl-extension.c: Use #ifdef HAVE_DLOPEN to hide dl* if it + is not available. + + * babl/Makefile.am: Removed win32_libs and added @LTLIBOBJS@ to + LIBADD to get the replacement for gettimeofday linked in if + needed. + + * babl/gettimeofday.c: New file to provide a replacement for + gettimeofday, only used on Windows yet. + 2007-01-06 Michael Schumacher * Makefile.am: don't go into the extensions subdirectory on diff --git a/babl/Makefile.am b/babl/Makefile.am index 81b28f9..6d26132 100644 --- a/babl/Makefile.am +++ b/babl/Makefile.am @@ -1,7 +1,6 @@ ## Source directory if OS_WIN32 -win32_libs = -lgw32c -lole32 -luuid -lwsock32 no_undefined = -no-undefined endif @@ -52,7 +51,7 @@ lib_LTLIBRARIES= libbabl.la libbabl_la_SOURCES= $(h_sources) $(c_sources) libbabl_la_LIBADD=\ base/libbase.la \ - ${win32_libs} + @LTLIBOBJS@ libbabl_la_LDFLAGS= \ -version-info $(BABL_LIBRARY_VERSION) \ diff --git a/babl/babl-conversion.c b/babl/babl-conversion.c index 7d472aa..2fe140f 100644 --- a/babl/babl-conversion.c +++ b/babl/babl-conversion.c @@ -17,11 +17,12 @@ * Boston, MA 02111-1307, USA. */ -#include "babl-internal.h" -#include "babl-db.h" + #include #include #include +#include "babl-internal.h" +#include "babl-db.h" static int each_babl_conversion_destroy (Babl *babl, diff --git a/babl/babl-extension.c b/babl/babl-extension.c index 49c9f16..8db2601 100644 --- a/babl/babl-extension.c +++ b/babl/babl-extension.c @@ -140,11 +140,6 @@ destroy_hook (void) #ifdef HAVE_DLFCN_H #include -#else -void *dlopen(const char *, int); -void *dlsym(void *, const char *); -int dlclose(void *); -char *dlerror(void); #endif #ifndef RTLD_NOW @@ -167,6 +162,7 @@ babl_extension_load (const char *path) { Babl *babl = NULL; +#ifdef HAVE_DLOPEN /* do the actual loading thing */ void *dl_handle = NULL; int (*init) (void) = NULL; @@ -196,6 +192,7 @@ babl_extension_load (const char *path) babl_log ("babl_extension_init() in extension '%s' failed (return!=0)", path); return load_failed (babl); } +#endif if (babl_db_insert (db, babl) == babl) { @@ -340,7 +337,7 @@ each_babl_extension_destroy (Babl *babl, { if (babl->extension.destroy) babl->extension.destroy(); -#ifdef BABL_DYNAMIC_EXTENSIONS +#ifdef HAVE_DLOPEN if (babl->extension.dl_handle) dlclose (babl->extension.dl_handle); #endif diff --git a/babl/babl-internal.h b/babl/babl-internal.h index 06d69c2..12fe70c 100644 --- a/babl/babl-internal.h +++ b/babl/babl-internal.h @@ -44,6 +44,11 @@ #include "babl-util.h" #include "babl-memory.h" +/* redefining some functions for the win32 platform */ +#ifdef _WIN32 +#define srandom srand +#define random rand +#endif Babl * babl_conversion_find (void *source, void *destination); diff --git a/babl/babl-model.c b/babl/babl-model.c index 573e2f3..2956aca 100644 --- a/babl/babl-model.c +++ b/babl/babl-model.c @@ -17,10 +17,10 @@ * Boston, MA 02111-1307, USA. */ -#include "babl-internal.h" #include #include #include +#include "babl-internal.h" #include "babl-db.h" diff --git a/babl/gettimeofday.c b/babl/gettimeofday.c new file mode 100644 index 0000000..c106082 --- /dev/null +++ b/babl/gettimeofday.c @@ -0,0 +1,66 @@ +/* + * timeval.h 1.0 01/12/19 + * + * Defines gettimeofday, timeval, etc. for Win32 + * + * By Wu Yongwei + * + */ + +#ifdef _WIN32 + +#define WIN32_LEAN_AND_MEAN +#include +#include + +#ifndef __GNUC__ +#define EPOCHFILETIME (116444736000000000i64) +#else +#define EPOCHFILETIME (116444736000000000LL) +#endif + +struct timeval { + long tv_sec; /* seconds */ + long tv_usec; /* microseconds */ +}; + +struct timezone { + int tz_minuteswest; /* minutes W of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; + + +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + FILETIME ft; + LARGE_INTEGER li; + __int64 t; + static int tzflag; + + if (tv) + { + GetSystemTimeAsFileTime(&ft); + li.LowPart = ft.dwLowDateTime; + li.HighPart = ft.dwHighDateTime; + t = li.QuadPart; /* In 100-nanosecond intervals */ + t -= EPOCHFILETIME; /* Offset to the Epoch time */ + t /= 10; /* In microseconds */ + tv->tv_sec = (long)(t / 1000000); + tv->tv_usec = (long)(t % 1000000); + } + + if (tz) + { + if (!tzflag) + { + _tzset(); + tzflag++; + } + tz->tz_minuteswest = _timezone / 60; + tz->tz_dsttime = _daylight; + } + + return 0; +} + +#endif /* _WIN32 */ diff --git a/configure.ac b/configure.ac index 4b9e996..a07ebf4 100644 --- a/configure.ac +++ b/configure.ac @@ -56,6 +56,7 @@ AC_SUBST(PACKAGE_NAME) AM_CONFIG_HEADER(config.h) AM_INIT_AUTOMAKE(no-define) +AC_DISABLE_STATIC AC_PROG_CC AC_LIBTOOL_WIN32_DLL AM_PROG_LIBTOOL @@ -162,6 +163,9 @@ dnl =========================================================================== AC_CHECK_LIB([dl], [dlopen], [DL_LIB="-ldl"]) AC_SUBST(DL_LIB) +AC_CHECK_FUNCS(dlopen) +AC_REPLACE_FUNCS(gettimeofday) + AC_DEFINE_UNQUOTED(BABL_PATH, "~/.babl-$BABL_API_VERSION:/usr/local/lib/babl-$BABL_API_VERSION:/usr/lib/babl-$BABL_API_VERSION", [search path for babl extensions (default value of enviroment variable)]) AC_DEFINE(BABL_PATH_SEPERATOR, "/", [string used to seperate directories in a path string]) AC_DEFINE(BABL_LIST_SEPERATOR, ':', [seperator between paths in BABL_PATH]) -- 2.30.2